package object;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

public class GameObject {
	protected short []	m_indices = {
			1
	};
	protected float []	m_vertices = {
			0.0f,	0.0f,	0.0f
	};
	public float []	m_colors = {
			0.0f,	0.0f,	0.0f,	1.0f
	};
	public float []	m_texture = {
			0.0f,	0.0f,	//0
			0.0f,	1.0f,	//1
			1.0f,	1.0f,	//2
			1.0f,	0.0f	//3
	};
	public FloatBuffer m_vertexBuffer;
	public ShortBuffer m_indexBuffer;
	public FloatBuffer m_colorBuffer;
	public FloatBuffer m_textureBuffer;
	//------------------------------------------------------------
	/// This function create float buffer from array of float
	/// @param one array of float
	/// @return float buffer was created from this array 
	//------------------------------------------------------------
	public FloatBuffer CreateFloatBuffer(float [] arr){
		FloatBuffer floatBuffer;
		ByteBuffer bb = ByteBuffer.allocateDirect(arr.length*4);
		bb.order(ByteOrder.nativeOrder());
		floatBuffer = bb.asFloatBuffer();
		floatBuffer.put(arr);
		floatBuffer.position(0);
		return floatBuffer;
	}
	//------------------------------------------------------------
	/// This function create short buffer from array of short
	/// @param one array of float
	/// @return short buffer was created from this array 
	//------------------------------------------------------------
	public ShortBuffer CreateShortBuffer(short [] arr){
		ShortBuffer shortBuffer;
		ByteBuffer bb = ByteBuffer.allocateDirect(arr.length*2);
		bb.order(ByteOrder.nativeOrder());
		shortBuffer = bb.asShortBuffer();
		shortBuffer.put(arr);
		shortBuffer.position(0);
		return shortBuffer;
	}
	public void Init(){
		this.m_vertexBuffer = CreateFloatBuffer(m_vertices);
		this.m_indexBuffer = CreateShortBuffer(m_indices);
		this.m_colorBuffer = CreateFloatBuffer(m_colors);
		this.m_textureBuffer = CreateFloatBuffer(m_texture);
	}
}
